package com.lin.learning.questionmanagement.controller;
import com.lin.learning.questionmanagement.dto.AddQuestionDto;
import com.lin.learning.questionmanagement.dto.GetQuestionsDto;
import com.lin.learning.questionmanagement.dto.UpdateQuestionDto;
import com.lin.learning.questionmanagement.service.QuestionService;
import com.our.learning.infrastructure.pojo.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author : PanicLin
 * @date : 2023-06-17
 */
@RestController
@RequestMapping("/question")
public class QuestionController {

    @Autowired
    private final QuestionService questionService;



    public QuestionController(QuestionService questionService) {
        this.questionService = questionService;
    }

    @GetMapping("/questionlist/{type}")
    public ResponseResult getQuestionsByType(Integer pageNum, Integer pageSize,@PathVariable String type){
        return questionService.getQuestionsByType(pageNum,pageSize,type);
    }

    @GetMapping
    public ResponseResult getQuestions(@RequestBody GetQuestionsDto getQuestionsDto){
        return questionService.getQuestions(getQuestionsDto);
    }

    @GetMapping("/questionlist")
    public ResponseResult questionList(Integer pageNum, Integer pageSize){
        return questionService.questionList(pageNum,pageSize);
    }

    @PostMapping
    public ResponseResult addQuestion(@RequestBody AddQuestionDto addQuestionDto){
        return questionService.addQuestion(addQuestionDto);
    }

    @DeleteMapping("/{id}")
    public ResponseResult deleteQuestion(@PathVariable Integer id){
        return questionService.deleteQuestion(id);
    }

    @PutMapping
    public ResponseResult updateQuestion(@RequestBody UpdateQuestionDto updateQuestionDto){
        return questionService.updateQuestion(updateQuestionDto);
    }

    @GetMapping("/{id}")
    public ResponseResult getQuestionById(@PathVariable Integer id){
        return  questionService.getQuestionById(id);
    }
}
